#include <iostream>
using namespace std;
const int N = 1e5 + 10;
int a[N];
int n;

// 查找第一个大于等于t的位置
int upper(int t)
{
    int l = 1, r = n;
    while(l < r)
    {
        int mid = l + (r - l) / 2;
        if(a[mid] >= t) r = mid;
        else l = mid + 1;
    }
    if(a[l] < t) return 0;
    return l;
}

// 查找第一个小于等于t的位置
int lower(int t)
{
    int l = 1, r = n;
    while(l < r)
    {
        int mid = l + (r - l + 1) / 2;
        if(a[mid] <= t) l = mid;
        else r = mid - 1;
    }
    if(a[l] > t) return 0;
    return r;
}

int main()
{
    cin >> n;
    for(int i = 1;i <= n;i++) cin >> a[i];

    int q;
    cin >> q;
    while(q--)
    {
        int x, y;
        cin >> x >> y;
        int l = upper(x);
        // 考虑极端情况，x大于所有数
        if(l == 0)
        {
            cout << 0 << endl;
            continue;
        }
        int r = lower(y);
        // 考虑极端情况，y小于所有数
        if(r == 0)
        {
            cout << 0 << endl;
            continue;
        }
        cout << (r - l + 1) << endl;
    }
    return 0;
}